
function sysRadioCompare(a, b) {
	return a == b;
}

function parseXML(text) {
	text = text.replace(/^<\?xml\s+version\s*=\s*(["'])[^\1]+\1[^?]*\?>/, "");

	return new XML(text);
}

function __constructDate(t) {
	return new Date(t)
}

DataObject.prototype.bindControl = function(ctl) {
	if (this._boundControls == null)
		this._boundControls = []
	this._boundControls.push(ctl)
}

DataObject.prototype.commit = function() {
	if (this._boundControls != null) {
		for (var idx = 0; idx < this._boundControls.length; idx++) {
			var ctl = this._boundControls[idx]
			if (ctl.commitBinding)
				ctl.commitBinding(this)
		}
	}
	if (this.currentDataset != null)
		return this.currentDataset
	else
		return this.currentValue
}

DataObject.prototype.revert = function(v) {
	if (this._boundControls != null) {
		for (var idx = 0; idx < this._boundControls.length; idx++) {
			var ctl = this._boundControls[idx]
			if (ctl.loadBinding)
				ctl.loadBinding(this)
		}
	}
}

DataObject.prototype.setValue = function(v) {
	this.currentValue = v
	this.revert()
}

DataObject.prototype.getValue = function() {
	return this.currentValue
}

DataObject.prototype.__defineSetter__("value", function(v) { this.setValue(v); });
DataObject.prototype.__defineGetter__("value", function() { return this.getValue(); });

DataObject.prototype.getDataset = function() {
	return this.currentDataset
}

DataObject.prototype.setDataset = function(v) {
	this.currentDataset = v
	this.currentRow = 0
	this.revert()
}

DataObject.prototype.__defineSetter__("dataset", function(v) { this.setDataset(v); });
DataObject.prototype.__defineGetter__("dataset", function() { return this.getValue(); });

DataObject.prototype.getCount = function() {
	if (this.currentDataset != null)
		return this.currentDataset.rows.length
	else if (this.currentValue != null)
		return 1;
	else
		return 0;
}

DataObject.prototype.__defineGetter__("count", function() { return this.getCount(); });

DataObject.prototype.getRow = function() {
	return this.currentRow
}

DataObject.prototype.setRow = function(v) {
	this.currentRow = v
	this.revert()
}

DataObject.prototype.__defineGetter__("row", function() { return this.getRow(); });
DataObject.prototype.__defineSetter__("row", function(v) { this.setRow(v); });

DataObject.prototype.getField = function(fieldName) {
	return this.getRowField(this.currentRow, fieldName)
}

DataObject.prototype.getRowField = function(row, fieldName) {
	if (this.currentDataset != null) {
		if (row >= 0 && row < this.currentDataset.rows.length) {
			var fieldIdx = this.currentDataset.columns.indexOf(fieldName)
			if (fieldIdx < 0)
				return null;
			return this.currentDataset.rows[row][fieldIdx]
		}
		return null;
	}
	if (this.currentValue == null)
		return null;
	return this.currentValue[fieldName]
}

DataObject.prototype.setField = function(fieldName, v) {
	if (this.currentDataset != null) {
		if (this.currentRow < this.currentDataset.rows.length) {
			var fieldIdx = this.currentDataset.columns.indexOf(fieldName)
			if (fieldIdx < 0)
				return null;
			this.currentDataset.rows[this.currentRow][fieldIdx] = v
		}
	} else if (this.currentValue != null) {
		this.currentValue[fieldName] = v
	}
}
